﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyLib.Data {
	/// <summary>
	/// 
	/// </summary>
	public class NameObjectCollection : System.Collections.Specialized.NameObjectCollectionBase {
		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public object this[string key] {
			get { return BaseGet(key); }
			set { BaseSet(key, value); }
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public bool IsNullOrEmpty(string key) {
			var v = BaseGet(key);
			if (v == null || v == DBNull.Value)
				return true;
			else
				return string.IsNullOrEmpty(Convert.ToString(BaseGet(key)));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public int GetInt32(string key) {
			return Convert.ToInt32(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public short GetInt16(string key) {
			return Convert.ToInt16(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public long GetInt64(string key) {
			return Convert.ToInt64(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public decimal GetDecimal(string key) {
			return Convert.ToDecimal(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public DateTime GetDateTime(string key) {
			return Convert.ToDateTime(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public float GetFloat(string key) {
			return Convert.ToSingle(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public double GetDouble(string key) {
			return Convert.ToDouble(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public bool GetBoolean(string key) {
			var bv = Convert.ToString(BaseGet(key));

			if (string.IsNullOrEmpty(bv))
				return false;

			bv = bv.ToLower();
			return bv == "1" || bv == "yes" || bv == "true";
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public string GetString(string key) {
			return Convert.ToString(BaseGet(key));
		}

		/// <summary>
		/// 
		/// </summary>
		public NameObjectCollection()
			: base(StringComparer.OrdinalIgnoreCase) {
		}
	} // end of NameObjectCollection.
}
